// gmx shines, thanks the great gmx
// cyx shines, thanks the great cyx
// freopen,froepen,ioi,akioi,ccf
// everyone plz, watch Arknights live
#include <bits/stdc++.h>
using namespace std;
constexpr int N(1e6);
int v[N+5],a[N+5],p[N+5],l[N+5],r[N+5];
int t[N+5];
vector<int> e2[N+5];
int main() {
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin.tie(nullptr)->sync_with_stdio(false);
    int T;cin>>T;
    while (T--) {
        int n,m,L,V;cin>>n>>m>>L>>V;
        for (int i{1};i<=n;++i) {
            cin>>p[i]>>v[i]>>a[i];
            l[i]=L+1;r[i]=L;
            if (v[i]>V&&a[i]>=0) l[i]=p[i],r[i]=L;
            else if (v[i]>V) {
                long long st{(1LL*v[i]*v[i]-1LL*V*V-1)/(-2*a[i])};
                if (st>L) st=L;
                l[i]=p[i];
                r[i]=p[i]+st;
            } else if (a[i]>0) {
                long long st{(1LL*V*V-1LL*v[i]*v[i])/(2*a[i])+1};
                if (st>L) st=L;
                l[i]=p[i]+st;
                r[i]=L;
            }
        }
        for (int i{1};i<=L+1;++i) t[i]=0,e2[i].clear();
        for (int i{1};i<=m;++i) {
            int p;cin>>p;
            ++t[p+1];
        }
        for (int i{0};i<=L;++i) t[i+1]+=t[i];
        int ans{0};
        for (int i{1};i<=n;++i) {
            if (r[i]>L) r[i]=L;
            if (l[i]<=r[i]&&t[r[i]+1]-t[l[i]]) {
                ++ans;
                ++l[i];
                ++r[i];
                e2[r[i]].push_back(i);
            }
        }
        int lst{0},res{m};
        for (int i{1};i<=L+1;++i)
            if (t[i]!=t[i-1]) {
                int j{i+1};
                while (t[j]==t[j-1]) ++j;
                for (int k{i};k<j;++k)
                    for (int z:e2[k])
                        if (l[z]>lst) {
                            --res;
                            lst=i;
                            goto bed;
                        }
                bed:;
                i=j-1;
            }
        cout<<ans<<" "<<res<<"\n";
    }
    return 0;
}